<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>花间村 - 编辑商品</title>
    <link rel="stylesheet" href="{{ asset('css/wechat_service_account.css') }}">
    <style>
        .container {
            padding: 15px;
        }

        .header {
            background: #fff;
            padding: 20px;
            border-radius: 12px;
            margin-bottom: 20px;
            box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
            text-align: center;
        }

        .header h2 {
            margin: 0;
            color: #333;
            font-size: 20px;
        }

        .back-btn {
            margin-top: 15px;
            padding: 12px 20px;
            background: #1890ff;
            color: white;
            border: none;
            border-radius: 20px;
            font-size: 14px;
            cursor: pointer;
            text-decoration: none;
            display: inline-block;
        }

        .back-btn:hover {
            background: #40a9ff;
        }

        .product-form {
            background: #fff;
            border-radius: 12px;
            padding: 20px;
            box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
        }

        .form-group {
            margin-bottom: 20px;
        }

        .form-label {
            display: block;
            margin-bottom: 5px;
            font-weight: 500;
            color: #333;
        }

        .form-control {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 16px;
            box-sizing: border-box;
        }

        .form-control:focus {
            outline: none;
            border-color: #1890ff;
        }

        .btn-primary {
            background: #1890ff;
            color: white;
            border: none;
            border-radius: 4px;
            padding: 12px 20px;
            font-size: 16px;
            cursor: pointer;
            width: 100%;
        }

        .btn-primary:hover {
            background: #40a9ff;
        }

        .btn-toggle {
            width: 100%;
            border: none;
            border-radius: 4px;
            padding: 12px 20px;
            font-size: 16px;
            cursor: pointer;
            color: white;
        }

        .btn-toggle-up {
            background: #52c41a;
        }

        .btn-toggle-down {
            background: #ff4d4f;
        }

        .product-images {
            margin-top: 30px;
        }

        .images-title {
            font-size: 18px;
            font-weight: 500;
            margin-bottom: 15px;
            color: #333;
        }

        .image-gallery {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
            gap: 10px;
        }

        .image-item {
            position: relative;
        }

        .image-item img {
            width: 100%;
            height: 100px;
            object-fit: cover;
            border-radius: 4px;
        }

        .alert {
            padding: 10px;
            border-radius: 4px;
            margin-bottom: 20px;
        }

        .alert-success {
            background: #f6ffed;
            border: 1px solid #b7eb8f;
            color: #52c41a;
        }

        .alert-error {
            background: #fff2f0;
            border: 1px solid #ffccc7;
            color: #ff4d4f;
        }
    </style>
</head>

<body>
    <div class="container">
        <div class="header">
            <h2>编辑商品</h2>
            <a href="{{ route('wechat.service.account.inventory') }}" class="back-btn">返回库存管理</a>
        </div>

        @if(session('success'))
        <div class="alert alert-success">
            {{ session('success') }}
        </div>
        @endif

        @if(session('error'))
        <div class="alert alert-error">
            {{ session('error') }}
        </div>
        @endif

        <div class="product-form">
            <form action="{{ route('wechat.service.account.product.update', $product->id) }}" method="POST">
                @csrf
                @method('PUT')

                <div class="form-group">
                    <label for="name" class="form-label">商品名称</label>
                    <input type="text" 
                           class="form-control" 
                           id="name" 
                           name="name" 
                           value="{{ old('name', $product->name) }}" 
                           required>
                </div>

                <div class="form-group">
                    <label for="price" class="form-label">价格</label>
                    <input type="number" 
                           class="form-control" 
                           id="price" 
                           name="price" 
                           value="{{ old('price', $product->price) }}" 
                           step="0.01" 
                           required>
                </div>

                <div class="form-group">
                    <label for="stock" class="form-label">库存</label>
                    <input type="number" 
                           class="form-control" 
                           id="stock" 
                           name="stock"
                           value="{{ old('stock', $product->stock) }}">
                    <small style="color: #666;">请输入商品库存数量</small>
                </div>

                <div class="form-group">
                    <label for="description" class="form-label">商品描述</label>
                    <textarea class="form-control" 
                              id="description" 
                              name="description" 
                              rows="4">{{ old('description', $product->description) }}</textarea>
                </div>

                <button type="submit" class="btn-primary">保存修改</button>
            </form>

            <hr style="margin: 30px 0;">

            <form action="{{ route('products.toggle-sale', $product) }}" method="POST">
                @csrf
                @method('PATCH')
                
                <button type="submit" 
                        class="btn-toggle {{ $product->status ? 'btn-toggle-down' : 'btn-toggle-up' }}">
                    {{ $product->status ? '下架商品' : '上架商品' }}
                </button>
            </form>
        </div>

        <div class="product-images">
            <div class="images-title">商品图片（只读展示）</div>
            @if($product->hasMedia('product-images'))
            <div class="image-gallery">
                @foreach($product->getMedia('product-images') as $media)
                <div class="image-item">
                    <img src="{{ $media->getUrl() }}" alt="{{ $media->name }}">
                </div>
                @endforeach
            </div>
            @else
            <p style="color: #666;">暂无商品图片</p>
            @endif
        </div>
    </div>
</body>

</html>